package com.eshop.dao.Impl;

import com.eshop.dao.UserDao;
import com.eshop.model.User;

public class UserDaoImpl extends BaseDao implements UserDao {
    @Override
    public void addUser(User user) {
        String sql = "INSERT INTO `eshop0`.`t_user`(`user_name`, `user_pass`, `user_age`, `user_sex`, `user_email`, `user_rank`) VALUES (?,?,?,?,?,?)";
        update(sql,user.getUser_name(),user.getUser_pass(),user.getUser_age(),user.getUser_sex(),user.getUser_email(),user.getUser_rank());
    }

    @Override
    public void updateUser(User user) {
        String sql = "UPDATE `t_user` SET  `user_pass` = ?, `user_age` = ?, `user_sex` = ?, `user_email` = ?, `user_rank` = ? WHERE `user_name` = ?";
        update(sql,user.getUser_pass(),user.getUser_age(),user.getUser_sex(),user.getUser_email(),user.getUser_rank(),user.getUser_name());
    }

    @Override
    public User queryUserByUsername(String username) {
        String sql = "select * from t_user where user_name=?";
        return queryForOne(User.class,sql,username);
    }

    @Override
    public User queryUserByUsernameAndPassword(String username, String password) {
        String sql = "select * from t_user where user_name=? && user_pass=?";
        return queryForOne(User.class,sql,username,password);
    }
}
